//
//  FQDMySendOutCommentViewController.m
//  FakeQDaily
//
//  Created by mewxiv on 9/28/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDMySendOutCommentViewController.h"
#import "FQDQIconEmptyCell.h"
#import "FQDMyCommentCell.h"
#import "FQDNavigationView.h"
#import "FQDMyCommentMessageCellItem.h"
#import "FQDRestModel.h"

#import "FQDSimpleFeedCellItemProvider.h"
#import "Masonry.h"

@interface FQDMySendOutCommentViewController ()

@property (nonatomic, strong) FQDNavigationView *navView;

@end

@implementation FQDMySendOutCommentViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationView];
    [self setupCellItemProvider];
    [self loadNewCellItemsWithCompletion:nil];
}


- (void)setupNavigationView
{
    self.navView = [[FQDNavigationView alloc] init];
    self.navView.titleLabel.text = @"我发出的评论";
    self.navView.showBlurBg = YES;
    [self.navView.backButton addTarget:self action:@selector(popBack:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.navView];
    
    WeakSelf;
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.and.right.equalTo(weakSelf.view);
        make.height.equalTo(@64);
    }];
    
    [self.feedContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.navView.mas_bottom);
        make.left.right.and.bottom.equalTo(weakSelf.view);
    }];
}

- (void)setupCellItemProvider
{
    FQDSimpleFeedCellItemProvider *provider = [[FQDSimpleFeedCellItemProvider alloc] init];
    provider.responseFeedsName = @"comments";
    provider.responseFeedClass = [FQDMyCommentMessage class];
    provider.cellItemClass = [FQDMyCommentMessageCellItem class];
    [provider setFetchFeedBlock:^(NSString *feedId, NSString *cursorKey, QDailyAPICompleteBlock completion) {
        [[QDailyAPI sharedAPI] getMySendOutComments:cursorKey completion:completion];
    }];
    self.provider = provider;
}

#pragma mark - Event response
- (void)popBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

#pragma mark - FQDFeedBaseViewController DataSource
- (NSArray *)cellClasses
{
    return @[
        [FQDMyCommentCell class],
        [FQDQIconEmptyCell class],
    ];
}


- (NSInteger)numberOfHeaderCellsInCollectionView:(UICollectionView *)collectionView
{
    BOOL hasFeeds = [self.provider.cellItems count] > 0;
    BOOL hasMoreCellItems = [self.provider hasMoreCellItems];
    BOOL shouldShowEmptyCell = (!hasFeeds && !hasMoreCellItems);
    NSInteger headerCount = (shouldShowEmptyCell) ? 1 : 0;
    return headerCount;
}

- (Class)headerCellClassAtIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView
{
    if (indexPath.section == 0) {
        return [FQDQIconEmptyCell class];
    }
    return nil;
}

- (Class)cellClassForCellItem:(FQDFeedCellItem *)cellItem
{
    return [FQDMyCommentCell class];
}
#pragma mark - FQDFeedBaseViewController Deleagte
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForHeaderCellAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize cvSize = collectionView.frame.size;
    return cvSize;
}

- (void)configureHeaderCell:(UICollectionViewCell *)headerCell atIndexPath:(NSIndexPath *)indexPath inCollectionView:(UICollectionView *)collectionView
{
    if (indexPath.section == 0) {
        FQDQIconEmptyCell *emptyCell = (FQDQIconEmptyCell *)headerCell;
        emptyCell.titleText = @"我发出的评论会出现在这里";
    }
}

@end
